<?php

/**
 * Created by PhpStorm.
 * User: Leen
 * Date: 2016/1/4
 * Time: 15:57
 */

namespace App\Http\Requests\Front\address;

use App\Http\Requests\Request;

class AddAddressRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {
        $rules =  [
            //'user_id' => 'required|exists:user,id',
            // 'id_card' => 'required|alpha_num|size:18',
            'id_card' => array('required','regex:/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)|[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/'),
            // 'id_card' => array('regex:/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)|[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/'),
            'consignee' => 'required|max:60',
            //'country' => 'required|max:60',
            //'province' => 'required|max:60',
            'city' => 'required|max:60',
            'district' => 'required|max:120',
            'address' => 'required|max:120',
            'mobile' => 'required|size:11',
            'is_default' => 'in:0,1',
        ];
        return $rules;

    }

    /**
     * 验证信息
     * @return array
     */

    public function messages()
    {
        return [
            'id_card.required'  => '身份证信息不能为空',
            /*'id_card.alpha_num'  => '身份证号仅允许数字字母',
            'id_card.size'  => '身份证号必须是18位',*/
            'id_card.regex'  => '身份证号格式有误',

            'consignee.required'  => '收货人不能为空',
            'consignee.max'  => '收货人最大长度为60个字符',

            /*'country.required'=>'国家不能为空',
            'country.max'=>'国家最大长度为60个字符',

            'province.required'=>'省份不能为空',
            'province.max'=>'省份最大长度为60个字符',*/

            'city.required'=>'城市不能为空',
            'city.max'=>'城市最大长度为60个字符',

            'district.required'=>'街道不能为空',
            'district.max'=>'街道最大长度为120个字符',

            'address.required'=>'详细地址不能为空',
            'address.max'=>'详细地址最大长度为120个字符',

            'mobile.required'=>'手机号码不能为空',
            'mobile.size'  => '手机号码必须是11位',

            'is_default.in'  => '默认地址的值不正确',
        ];
    }
}